/*
 * @lc app=leetcode.cn id=223 lang=java
 *
 * [223] 矩形面积
 */

// @lc code=start
class Solution {
    /**
     * Accepted
    3080/3080 cases passed (1 ms)
    Your runtime beats 100 % of java submissions
    Your memory usage beats 87.74 % of java submissions (40.5 MB)
     */
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int s1 = (ax2 - ax1) * (ay2 - ay1);
        int s2 = (bx2 - bx1) * (by2 - by1);
        int x = Math.min(ax2, bx2) - Math.max(ax1, bx1);
        int y = Math.min(ay2, by2) - Math.max(ay1, by1);
        if (x <= 0 || y <= 0)
            return s1 + s2;
        return s1 + s2 - x * y;
    }
}
// @lc code=end
